﻿using MediatR;
using Microsoft.AspNetCore.Mvc;
using RedDragon.Common.Domain.AuthorizeRBAC;
using RedDragon.Common.Dtos;
using RedDragon.RBAC.API.Application.Common.Role;
using T.Common.Domain.Common;

namespace RedDragon.RBAC.API.Controllers
{
    /// <summary>
    /// 角色控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class RolesController : ControllerBase
    {
        private readonly IMediator mediator;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator"></param>
        public RolesController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 角色添加
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> AddRoles(CreateRolesCommand cmd)
        {
            return await mediator.Send(cmd);
        }
        /// <summary>
        /// 角色列表
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Result> SearchRoles([FromQuery] SearchRolesCommand cmd)
        {
            return await mediator.Send(cmd);
        }

        /// <summary>
        /// 无条件角色列表
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> QueryRoles(QueryRolesCommand cmd)
        {
            return await mediator.Send(cmd);
        }
    }
}
